﻿app.controller("studentController", function ($scope, studentService, $window,tutorService) {

    tutorService.getListByFilter().then(function (results) {
        $scope.tutorList = results.data;
    }, function (error) {
        console.log(error.data.message);
    });

    $scope.hola = function () {
        console.log($scope.Nombre);
    }
    $scope.list = [];

    $scope.lis = function () {
        studentService.getList().then(function (results) {
            $scope.list = results.data;
        }, function (error) {
            console.log(error.data.message);
        });
    }

    $scope.getById = function (student) {
        $scope.student = student;
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    };

    $scope.save = function () {
        if ($scope.student.Id) {
            studentService.update({ Id: "" }, $scope.student).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {   
                console.log(error.data.message);
            });
        } else {
            studentService.create($scope.student).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }
    $scope.delete = function (student) {
        if ($window.confirm('Confirm delete')) {
            studentService.delete({ Id: student.Id }).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
    }
    $scope.lis();
    $scope.formVisibility = false;
    $scope.ShowForm = function () {
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }
    $scope.cancel = function () {
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }

});